//
//  CommonViewController.m
//  Supermarket
//
//  Created by qskj-ios on 2018/12/10.
//  Copyright © 2018年 com.qiansheng. All rights reserved.
//

#import "CommonViewController.h"
#import "ScoreListViewController.h"
#import "OffsetListViewController.h"
#import "LeaseListViewController.h"
#import "BookListViewController.h"

@interface CommonViewController ()<FJSlidingControllerDataSource, FJSlidingControllerDelegate, UINavigationControllerDelegate>

@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) NSArray *controllers;

@end

@implementation CommonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.datasouce = self;
    self.delegate = self;
    
    ScoreListViewController *scoreVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ScoreListViewController"];
    scoreVC.parentController = self;
    
    OffsetListViewController *offsetVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"OffsetListViewController"];
    offsetVC.parentController = self;
    
    LeaseListViewController *leaseVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LeaseListViewController"];
    leaseVC.parentController = self;
    leaseVC.topHeight = TopHeight;
    
    BookListViewController *bookVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"BookListViewController"];
    bookVC.parentController = self;
    bookVC.topHeight = TopHeight;
    
    self.titles = @[@"积分抵用", @"消费抵用券", @"便民租赁", @"借/还书"];
    self.controllers = @[scoreVC, offsetVC, leaseVC, bookVC];
    [self addChildViewController:scoreVC];
    [self addChildViewController:offsetVC];
    [self addChildViewController:leaseVC];
    [self addChildViewController:bookVC];
    
    [self reloadData];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [[UserInfoManager sharedManager] removeUserInfoData];
}

#pragma mark - FJSlidingControllerDataSoure

- (NSInteger)numberOfPageInFJSlidingController:(FJSlidingController *)fjSlidingController {
    return self.titles.count;
}
- (UIViewController *)fjSlidingController:(FJSlidingController *)fjSlidingController controllerAtIndex:(NSInteger)index {
    return self.controllers[index];
}
- (NSString *)fjSlidingController:(FJSlidingController *)fjSlidingController titleAtIndex:(NSInteger)index {
    return self.titles[index];
}

/*
 - (UIColor *)titleNomalColorInFJSlidingController:(FJSlidingController *)fjSlidingController;
 - (UIColor *)titleSelectedColorInFJSlidingController:(FJSlidingController *)fjSlidingController;
 - (UIColor *)lineColorInFJSlidingController:(FJSlidingController *)fjSlidingController;
 - (CGFloat)titleFontInFJSlidingController:(FJSlidingController *)fjSlidingController;
 */

#pragma mark - FJSlidingControllerDelegate

- (void)fjSlidingController:(FJSlidingController *)fjSlidingController selectedIndex:(NSInteger)index {
    // presentIndex
}
- (void)fjSlidingController:(FJSlidingController *)fjSlidingController selectedController:(UIViewController *)controller {
    
}
- (void)fjSlidingController:(FJSlidingController *)fjSlidingController selectedTitle:(NSString *)title {
    // presentTitle
}

//- (void)viewWillAppear:(BOOL)animated {
//    [super viewWillAppear:animated];
//
//    [self.navigationController setNavigationBarHidden:YES animated:YES];
//}
//
//- (void)viewWillDisappear:(BOOL)animated {
//    [super viewWillDisappear:animated];
//
//    [self.navigationController setNavigationBarHidden:NO animated:YES];
//}
//
//#pragma mark - UINavigationControllerDelegate
//
///** 隐藏导航栏 **/
//- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(nonnull UIViewController *)viewController animated:(BOOL)animated {
//    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
//    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
